/*
 * Copyright (c) 2019 - 2020 IoT Company of Midea Group.
 *
 * File Name 	    :
 * Description	    : HAL adaptor
 *
 * Version	        : v0.1
 * Author			:
 * Date	            :
 * History	        :
 */
#ifndef __MS_HAL_WIFI_H__
#define __MS_HAL_WIFI_H__

#include <stdint.h>
#include "ms_hal.h"
#include "ms_osal.h"
#include <stdbool.h>

/**
 * !!! please see the config.mk to make sure your chip whether had those function !!!
 * MS_CONFIG_NT_SUPPORT
 * MS_CONFIG_FA_SUPPORT
 * MS_CONFIG_SNIFFER_SUPPORT
 * MS_CONFIG_ERRCODE_SUPPORT
 * !!! if not, do not adapter following interfaces
 */

#ifdef __cplusplus
extern "C" {
#endif

#define MS_DEFAULT_AP_SCAN_NUMBER				25
#define HAL_MAX_SSID_LEN 						32
#define ETH_ALEN 								6


typedef enum
{
	/*  wifi event    */
	MS_HAL_EVT_LINK_LOST				= 0x10,
	MS_HAL_EVT_ASSOC					= 0x11,
	MS_HAL_EVT_CHANNEL_SWITCH			= 0x12,
	MS_HAL_EVT_NETWORK_RESET			= 0x13,
	MS_HAL_EVT_DHCP_RENEW				= 0x14,
	/*  sta event.     */
	MS_HAL_EVT_STA_CONNECT_IPV4_SUCCESS	= 0x82,
    MS_HAL_EVT_STA_CONNECT_IPV6_SUCCESS	= 0x83,
	MS_HAL_EVT_STA_CONNECT_FAILED		= 0x84,
	/*  ap event.      */
	MS_HAL_EVT_AP_START_SUCCESS			= 0xC2,
	MS_HAL_EVT_AP_START_FAILED			= 0xC4,
	MS_HAL_EVT_AP_STOP_SUCCESS			= 0xC5,
	MS_HAL_EVT_AP_STOP_FAILED			= 0xC6,
	/*  sniffer event.      */
	MS_HAL_EVT_SNIFFER_SUCCESS 			= 0xa1,
	MS_HAL_EVT_SNIFFER_FAILED			= 0xa2,
	MS_HAL_EVT_NONE			            = 0xFF,
}ms_hal_wifi_event_t;

typedef struct
{
	/* ssid length */
	uint8_t len;
	/* ssid name(AP name)	*/
	uint8_t	val[HAL_MAX_SSID_LEN + 1];
}ms_hal_wifi_ssid_t;

typedef struct
{
	/*unique 6-byte MAC address */
	uint8_t mac_addr[6];
}ms_hal_wifi_mac_t;


typedef struct
{
	bool ipv4_effect;
	uint32_t ipv4_addr;
	bool ipv6_effect;
	uint32_t ipv6_addr[4];
}ms_hal_wifi_ip_t;

typedef enum
{
	MS_HAL_WIFI_BSS_TYPE_INFRASTRUCTURE		= 0x00,
	MS_HAL_WIFI_BSS_TYPE_ADHOC				= 0x01,
	MS_HAL_WIFI_BSS_TYPE_BOTH				= 0x02,
}ms_hal_wifi_bss_type_t;

typedef enum
{
	 /* Denotes 5GHz radio band */
    MS_HAL_WIFI_802_11_BAND_5GHZ   = 0,
     /* Denotes 2.4GHz radio band */
    MS_HAL_WIFI_802_11_BAND_2_4GHZ = 1
} ms_hal_wifi_802_11_band_t;

// 模组重启原因
typedef enum
{
    MS_HAL_WIFI_PWR_ON_RST        = 0x00,
    MS_HAL_WIFI_SOFTWARE_RST      = 0x01,
    MS_HAL_WIFI_DEEP_SLEEP_RST    = 0x02,
    MS_HAL_WIFI_UNKNOWN_RST       = 0xFF
} ms_hal_wifi_reboot_reason_t;

// AP连接失败原因
typedef enum
{
    MS_HAL_WIFI_CONNECT_NONE        = 0x0,
    MS_HAL_WIFI_CONNECT_NO_AP       = 0x1,
    MS_HAL_WIFI_CONNECT_WRONG_PWD   = 0x2,
    MS_HAL_WIFI_CONNECT_DHCP_ERR    = 0x4,
    MS_HAL_WIFI_CONNECT_BEACON_LOST = 0x8
} ms_hal_wifi_connect_fail_reason_t;

// 关联状态码
typedef enum
{
    MS_HAL_WIFI_STATUS_CODE_SUCCESS = 0,                       /*!<  操作成功 */
    MS_HAL_WIFI_STATUS_CODE_FAIL,                              /*!<  未指定失败原因 */

    MS_HAL_WIFI_STATUS_CODE_NOT_SUPPORT_HIGH_REQUIREMENT = 10, /*!<  所要求的性能范围过广，无法支持 */
    MS_HAL_WIFI_STATUS_CODE_REFUSE_REASSOC,                    /*!<  拒绝重新关联；之前的关联无法识别与转移 */
    MS_HAL_WIFI_STATUS_CODE_REFUSE_ASSOC,                      /*!<  拒绝关联；原因是不在802.11标准所指定的范围内 */
    MS_HAL_WIFI_STATUS_CODE_NOT_SUPPORT_CRYPT,                 /*!<  不支持所使用的身份验证算法 */
    MS_HAL_WIFI_STATUS_CODE_IDENTITY_NUMBER_ERR,               /*!<  超乎预期的身份验证序号 */
    MS_HAL_WIFI_STATUS_CODE_RESPONSE_MSG_WRONG,                /*!<  身份验证被拒绝；响应信息有误 */
    MS_HAL_WIFI_STATUS_CODE_FRAME_NOT_IN_WINDOW,               /*!<  身份验证被拒绝；下一帧并未出现在预定的窗口内 */
    MS_HAL_WIFI_STATUS_CODE_RESOURCE_LIMITED,                  /*!<  关联被拒绝；接入点资源有限 */
    MS_HAL_WIFI_STATUS_CODE_NOT_SUPPORT_BSS_SPEED,             /*!<  关联被拒绝；工作站并未支持BSS要求的所有数据传输速率 */
    MS_HAL_WIFI_STATUS_CODE_NOT_SUPPORT_SHORT_PREAMBLE,        /*!<  关联被拒绝；工作站并未支持Short Preamble功能 */
    MS_HAL_WIFI_STATUS_CODE_NOT_SUPPORT_PBCC,                  /*!<  关联被拒绝；工作站并未支持PBCC调制功能 */
    MS_HAL_WIFI_STATUS_CODE_NOT_SUPPORT_CHANNEL_AGILITY,       /*!<  关联被拒绝；工作站并未支持Channel Agility功能 */
    MS_HAL_WIFI_STATUS_CODE_NOT_SUPPORT_SPECTRUM_MANAGEMENT,   /*!<  关联被拒绝；需要Spectrum Management功能 */
    MS_HAL_WIFI_STATUS_CODE_NOT_ACCEPT_POWER_CAPABILITY,       /*!<  关联被拒绝；不接受Power Capability值 */
    MS_HAL_WIFI_STATUS_CODE_NOT_ACCEPT_SUPPORT_CHANNELS,       /*!<  关联被拒绝；不接受Supported Channels */
    MS_HAL_WIFI_STATUS_CODE_NOT_SUPPORT_SHORT_SLOT_TIME,       /*!<  关联被拒绝；工作站并未支持Short Slot Time功能 */
    MS_HAL_WIFI_STATUS_CODE_NOT_SUPPORT_DSSS_OFDM,             /*!<  关联被拒绝；工作站并未支持DSSS-OFDM功能 */
    MS_HAL_WIFI_STATUS_CODE_REQUEST_HAS_BEEN_DECLINE = 37,     /*!<  This is not used in assoc response; ignore */
    MS_HAL_WIFI_STATUS_CODE_MESSAGE_ELEMENT_WRONG = 40,        /*!<  信息元素不正确 */
    MS_HAL_WIFI_STATUS_CODE_GROUP_PASSWORD_WRONG,              /*!<  成组（广播/组播）密码不正确 */
    MS_HAL_WIFI_STATUS_CODE_UNICAST_PASSWORD_WRONG,            /*!<  成对（单播）密码不正确 */
    MS_HAL_WIFI_STATUS_CODE_AKMP_WRONG,                        /*!<  身份验证与密钥管理协议（AKMP）不正确 */
    MS_HAL_WIFI_STATUS_CODE_NOT_SUPPORT_RSN_IE_VERSION,        /*!<  未支持的强健安全网络信息元素（RSN IE）版本 */
    MS_HAL_WIFI_STATUS_CODE_NOT_SUPPORT_RSN_IE_CAPABILITY,     /*!<  不支持此RSN IE性能（capability） */
    MS_HAL_WIFI_STATUS_CODE_PASSWORD_REFUSED_BY_STRATEGY       /*!<  密码组被使用策略拒绝 */

} ms_hal_wifi_status_code_t;

// 断联原因码
typedef enum
{
    MS_HAL_WIFI_DISASSOC_UNSPECIFIED = 1,                      /*!<  未指定 */
    MS_HAL_WIFI_DISASSOC_IDENTIFY_FAILURE,                     /*!<  之前的身份验证无效 */
    MS_HAL_WIFI_DISASSOC_STATION_LOST,                         /*!<  工作站已经离开基本服务区域或扩展服务区域，目前已经解除身份验证 */
    MS_HAL_WIFI_DISASSOC_INACTIVITY_TIMER_TIMEOUT,             /*!<  闲置计时器（inactivity timer）超时且工作站已经取消关联 */
    MS_HAL_WIFI_DISASSOC_RESOURCE_LIMITED,                     /*!<  接入点资源不足，因而取消关联 */
    MS_HAL_WIFI_DISASSOC_UNCERTIFIED_STATION,                  /*!<  从尚未认证的工作站收到的帧类型或子类型不正确 */
    MS_HAL_WIFI_DISASSOC_UNRELATED_STATION,                    /*!<  从尚未关联的工作站收到的帧类型或子类型不正确 */
    MS_HAL_WIFI_DISASSOC_STATION_LEFT,                         /*!<  工作站已经离开基本服务区域或扩展服务区域，目前已经取消关联 */
    MS_HAL_WIFI_DISASSOC_ASSOC_BEFORE_IDENTIFY,                /*!<  在身份验证完成之前要求关联或重新关联 */
    MS_HAL_WIFI_DISASSOC_NOT_ACCEPT_POWER_CAPABILITY,          /*!<  无法接受Power Capability信息元素的设定值，因而取消关联 */
    MS_HAL_WIFI_DISASSOC_NOT_ACCEPT_SUPPORTED_CHANNELS,        /*!<  无法接受Supported Channels信息元素的设定值，因而取消关联 */

    MS_HAL_WIFI_DISASSOC_MESSAGE_ELEMENT_WRONG = 13,           /*!<  信息元素不正确 */
    MS_HAL_WIFI_DISASSOC_MESSAGE_INCOMPLETE,                   /*!<  消息完整性校验失败 */
    MS_HAL_WIFI_DISASSOC_4_TIME_TIMEOUT,                       /*!<  4次密钥握手超时 */
    MS_HAL_WIFI_DISASSOC_GROUP_TIMEOUT,                        /*!<  组密钥握手超时 */
    MS_HAL_WIFI_DISASSOC_4_TIME_PARAM_ERR,                     /*!<  4次握手信息元素的安全参数与初始参数集不符 */
    MS_HAL_WIFI_DISASSOC_GROUP_PASSWORD_WRONG,                 /*!<  成组密码不正确 */
    MS_HAL_WIFI_DISASSOC_PAIR_PASSWORD_WRONG,                  /*!<  成对密码不正确 */
    MS_HAL_WIFI_DISASSOC_TREATY_WRONG,                         /*!<  身份验证与密钥管理协议不正确 */
    MS_HAL_WIFI_DISASSOC_NOT_SUPPORT_PSN_IE_VERSION,           /*!<  未支持的强健安全网络信息元素（PSN IE）版本 */
    MS_HAL_WIFI_DISASSOC_RSN_IE_CAPABILITY_WRONG,              /*!<  RSN IE的性能（capability）项不正确 */
    MS_HAL_WIFI_DISASSOC_802_1XIDETITY_FAIL,                   /*!<  802.1x身份验证失败 */
    MS_HAL_WIFI_DISASSOC_POLICY_REFUSE_PASSWORD                /*!<  所定义的使用策略（policy）拒绝所提议的密码组 */
} ms_hal_wifi_disassoc_reason_t;

typedef enum
{
    /* Active mode.*/
	MS_HAL_WIFI_SCAN_TYPE_ACTIVE 	= 0x00,
    /* Passive mode.*/
	MS_HAL_WIFI_SCAN_TYPE_PASSIVE 	= 0x01,
} ms_hal_wifi_scan_type_t;

#define MS_HAL_SHARED_ENABLED  	0x00008000
#define MS_HAL_WPA_SECURITY    	0x00200000
#define MS_HAL_WPA2_SECURITY   	0x00400000
#define MS_HAL_WPS_ENABLED     	0x10000000

#define MS_HAL_WEP_ENABLED     		0x0001
#define MS_HAL_TKIP_ENABLED         0x0002
#define MS_HAL_AES_ENABLED        	0x0004
#define MS_HAL_WSEC_SWFLAG        	0x0008
//TODO　重复定义
typedef enum
{
    MS_HAL_WIFI_SECURITY_OPEN           = 0,                                                				/* Open security                           		*/
    MS_HAL_WIFI_SECURITY_WEP_PSK        = MS_HAL_WEP_ENABLED,                                      			/* WEP Security with open authentication.*/
    MS_HAL_WIFI_SECURITY_WEP_SHARED     = ( MS_HAL_WEP_ENABLED | MS_HAL_SHARED_ENABLED ),                 	/* WEP Security with shared authentication 	*/
    MS_HAL_WIFI_SECURITY_WPA_TKIP_PSK   = ( MS_HAL_WPA_SECURITY  | MS_HAL_TKIP_ENABLED ),                 	/* WPA Security with TKIP                  		*/
    MS_HAL_WIFI_SECURITY_WPA_AES_PSK    = ( MS_HAL_WPA_SECURITY  | MS_HAL_AES_ENABLED ),                  	/* WPA Security with AES                   		*/
    MS_HAL_WIFI_SECURITY_WPA2_AES_PSK   = ( MS_HAL_WPA2_SECURITY | MS_HAL_AES_ENABLED ),                  	/* WPA2 Security with AES                  		*/
    MS_HAL_WIFI_SECURITY_WPA2_TKIP_PSK  = ( MS_HAL_WPA2_SECURITY | MS_HAL_TKIP_ENABLED ),                 	/* WPA2 Security with TKIP                 		*/
    MS_HAL_WIFI_SECURITY_WPA2_MIXED_PSK = ( MS_HAL_WPA2_SECURITY | MS_HAL_AES_ENABLED | MS_HAL_TKIP_ENABLED ),   /* WPA2 Security with AES & TKIP           	*/
    MS_HAL_WIFI_SECURITY_WPS_OPEN       = MS_HAL_WPS_ENABLED,                                      			/* WPS with open security                  		*/
    MS_HAL_WIFI_SECURITY_WPS_SECURE     = (MS_HAL_WPS_ENABLED | MS_HAL_AES_ENABLED),                      	/* WPS with AES security                   		*/
    MS_HAL_WIFI_SECURITY_UNKNOWN        = -1,                                                                        /**< May be returned by scan function if security is unknown. Do not pass this to the join function! */
    MS_HAL_WIFI_SECURITY_FORCE_32_BIT   = 0x7fffffff                                                                 /**< Exists only to force rtw_security_t type to 32 bits */
} ms_hal_wifi_security_t;

#pragma pack(1)
typedef struct
{
    ms_hal_wifi_ssid_t              	SSID;             /* Service Set Identification (i.e. Name of Access Point)					*/
    ms_hal_wifi_mac_t               	BSSID;            /* Basic Service Set Identification (i.e. MAC address of Access Point)       	*/
    int16_t               				signal_strength;  /* Receive Signal Strength Indication in dBm. <-90=Very poor, >-30=Excellent */
    uint32_t                  			max_data_rate;    /* Maximum data rate in kilobits/s                                           			*/
    ms_hal_wifi_bss_type_t          	bss_type;         /* Network type                                                              				*/
    ms_hal_wifi_security_t          	security;         /* Security type                                                            	 			*/
    uint8_t                   			channel;          /* Radio channel that the AP beacon was received on                          		*/
    ms_hal_wifi_802_11_band_t       	band;             /* Radio band                                                                				*/
    bool              					record_on_channel;/* True if scan result was recorded on the channel advertised in the packet  	*/
} ms_hal_wifi_scan_result_t;

typedef void (*ms_hal_wifi_scan_result_callback_t)( ms_hal_wifi_scan_result_t *result_list, uint8_t num);
#pragma pack()

#define MS_SSID_MAX_LENGTH	    32	///< 限定外部路由或模块ap模式ssid的最大长度是32字符
#define MS_PWD_MAX_LENGTH	    64	///< 设定外部路由或模块ap模式的pwd最长为64字符
#define MS_HOST_NAME_MAX_LENGTH	32	///< 设定设定设备host name最长为15字符
#define MS_SOFTAP_SSID_MAX_LENGTH MS_HOST_NAME_MAX_LENGTH

typedef struct{
	uint8_t ssid[MS_SSID_MAX_LENGTH + 1/*'\0'*/];	    /*!<  配网路由的ssid */
	uint8_t ssid_len;								    /*!<  ssid的长度 */
	uint8_t pwd[MS_PWD_MAX_LENGTH + 1/*'\0'*/];         /*!<  配网路由的pwd */
	uint8_t pwd_len;                                    /*!<  pwd的长度 */
	uint8_t chan;									    /*!<  配网时路由的信道，注：路由信道可能变动 */
    uint8_t bssid[6];                                   /*!<  配网时路由的bssid */
    uint8_t encryption;                                 /*!<  配网时路由的加密类型 */
    uint8_t device_host_name[MS_HOST_NAME_MAX_LENGTH];  /*!<  配网后设备在路由器后台显示的名称 */
    uint8_t device_host_name_len;                       /*!<  配网后设备在路由器后台显示的名称长度 */
//#ifdef MS_CONFIG_FA_SUPPORT
    uint8_t preSharedKey[32];
    int wapiPskType;
//#endif
//#ifdef MS_CONFIG_NT_SUPPORT
	uint8_t pmk[32];									/*!<  无感配网手机传给模组的pmk */
	uint8_t pmk_len;									/*!<  pmk的长度*/
//#endif
}ms_hal_wifi_route_t,ms_hal_wifi_softap_info_t;

/**
 * 扫描完毕信号强度值处理接口
 */
typedef void (*ms_hal_wifi_ap_power_callback_t)(char ap_power);

typedef struct{
    uint8_t use_bssid;
    ms_hal_wifi_ap_power_callback_t ap_power_cb;
}ms_hal_wifi_connect_param_t;

typedef struct
{
	uint8_t						number;					/* Specifies the max scan number of AP list*/
	ms_hal_wifi_scan_type_t 	scan_type;				/* Specifies whether the scan should be Active or Passive */
	ms_hal_wifi_bss_type_t		bss_type;				/* Specifies whether the scan should search for Infrastructure networks (those using  \
														an Access Point), Ad-hoc networks, or both types.*/
	ms_hal_wifi_ssid_t			*ssid;					/* If this is non-Null, then the scan will only search for networks using the specified SSID.	*/
	ms_hal_wifi_mac_t			*mac;					/* If this is non-Null, then the scan will only search for networks where the BSSID (MAC \
														address of the Access Point) matches the specified MAC address.*/
	ms_hal_wifi_scan_result_callback_t	callback;		/* the callback function which will receive and process the result data.	*/
	ms_hal_wifi_scan_result_t	*scan_result;			/* a pointer to a result storage structure.*/
}ms_hal_wifi_ap_scan_param_t;

/*
 *   ------------------------------
 *   |      |   0   | 1~13 |  >13 |
 *   ------------------------------
 *   | 带5G  |   10  |  5   |  9   |
 *   ------------------------------
 *   | 无5G  |   7   |  6   |  8   |
 *   ------------------------------
 */
typedef enum {
    MS_HAL_WIFI_ERRCODE_NONE                         = 0,
    MS_HAL_WIFI_ERRCODE_SSID_NOT_FOUND               = 1,
    MS_HAL_WIFI_ERRCODE_PWD_ERROR                    = 4,
    
    MS_HAL_WIFI_ERRCODE_5G_CH1_13_SSID_NOT_FOUND     = 5, //ap no found
    MS_HAL_WIFI_ERRCODE_CH1_13_SSID_NOT_FOUND        = 6, //adapt do not care
    MS_HAL_WIFI_ERRCODE_CH0_SSID_NOT_FOUND           = 7, //adapt do not care
    MS_HAL_WIFI_ERRCODE_CH_OTHER_SSID_NOT_FOUND      = 8, //adapt do not care
    MS_HAL_WIFI_ERRCODE_5G_CH_OTHER_SSID_NOT_FOUND   = 9, //adapt do not care
    MS_HAL_WIFI_ERRCODE_5G_CH0_SSID_NOT_FOUND        = 10, //adapt do not care
    
    MS_HAL_WIFI_ERRCODE_AUTH_FAILED                  = 11,
    MS_HAL_WIFI_ERRCODE_ASSOC_FAILED                 = 12,
    MS_HAL_WIFI_ERRCODE_DHCP_FAILED                  = 13,

    MS_HAL_WIFI_ERRCODE_DNS_ERROR                    = 20,
    
    MS_HAL_WIFI_ERRCODE_TCP_FAILED                   = 21,
    MS_HAL_WIFI_ERRCODE_SST_FAILED                   = 22,
    MS_HAL_WIFI_ERRCODE_LOGIN_CMD_FAILED             = 23,
    MS_HAL_WIFI_ERRCODE_ADS_DNS_ERROR                = 24,
    MS_HAL_WIFI_ERRCODE_ADS_TCP_FAILED               = 25,
    MS_HAL_WIFI_ERRCODE_ADS_ID_FAILED                = 26,
    MS_HAL_WIFI_ERRCODE_ACCESS_DOMIAN_FAILED         = 27,
    MS_HAL_WIFI_ERRCODE_TARGET_SSID_RSSI_WEAK        ,//Only used by 0x0D lan status notify，not assign enum num
    MS_HAL_WIFI_ERRCODE_CONNECT_SERVER,
    MS_HAL_WIFI_ERRCODE_CONNECT_FAIL_UNKNOW          = 0xF0,
    MS_HAL_WIFI_ERRCODE_BEACON_LOST,
    MS_HAL_WIFI_ERRCODE_CONNECT_CLEAR                ,//adapt do not care
    MS_HAL_WIFI_ERRCODE_LOGIN_CLEAR                  ,//adapt do not care
}ms_hal_wifi_errcode_t;

#define MS_HAL_CHANNEL_TABLE_NUM_MAX 10
typedef struct {
    uint8_t first_channel;        /**< The first channel in the single channel table.*/
    uint8_t num_of_channel;       /**< The number of channels in the single channel table.*/
    uint8_t max_tx_power;         /**< The maximum transmit power in the single channel table, the unit is dBm.*/
    uint8_t dfs_req;              /**< 0: No DFS request, 1: DFS request.*/
} ms_hal_wifi_channel_table_t;

/** @brief This structures provide the country code information.
*/
typedef struct {
    uint8_t country_code[4];                /**< Country code string.*/
    uint8_t num_of_channel_table;           /**< Number of channel table.*/
    ms_hal_wifi_channel_table_t channel_table[MS_HAL_CHANNEL_TABLE_NUM_MAX];   /**< The details of each channel table, please refer to #wifi_channel_table_t.*/
} ms_hal_wifi_country_code_t;

/**
 * @brief ms_hal_wifi_status_report_func_t callback
 * @note  
 * @param errcode[in], please see ms_hal_wifi_errcode_t
 * @return ms_hal_result_t
 */
typedef int (*ms_hal_wifi_status_report_func_t)(ms_hal_wifi_errcode_t errcode,uint16_t *status_code,uint16_t *reason_code);

/**
 * @brief ms_hal_wifi_event_handler_t callback
 * @note  
 * @param event[in], please see ms_hal_wifi_event_t
 * @param data[in], any useful value
 * @return ms_hal_result_t
 */
typedef void (*ms_hal_wifi_event_handler_t)(ms_hal_wifi_event_t event, void *data);

/**
 * @brief get wifi mac
 * @note  
 * @param p_mac[out], uint8_t buffer
 * @return ms_hal_result_t
 */
ms_hal_result_t ms_hal_wifi_get_mac_address(uint8_t *p_mac);

typedef enum
{
    MS_HAL_WIFI_IP_TYPE_IPV4,
    MS_HAL_WIFI_IP_TYPE_IPV6,
    MS_HAL_WIFI_IP_TYPE_ALL,
} ms_hal_wifi_ip_type_t;

/**
 * @brief get wifi ip address
 * @note  if wifi in ap model, return ap ip address.
 *        if wifi in sta model, return sta ip address.
 * @param ip[out], ms_hal_wifi_ip_t
 * @return ms_hal_result_t
 */
ms_hal_result_t ms_hal_wifi_get_ip_address(ms_hal_wifi_ip_type_t type, ms_hal_wifi_ip_t *ip);

/**
 * @brief get wifi rssi value
 * @note  
 * @param rssi[out], int32_t
 * @return ms_hal_result_t
 */
ms_hal_result_t ms_hal_wifi_get_rssi(int32_t *rssi);

/**
 * @brief get wifi bssid
 * @note  if wifi in sta model, return sta bssid.
 * @param bssid[out], uint8_t
 * @return ms_hal_result_t
 */
ms_hal_result_t ms_hal_wifi_get_bssid(uint8_t *bssid);

/**
 * @brief get wifi channel value
 * @note  if wifi in ap model, return ap channel.
 *        if wifi in sta model, return sta channel.
 * @param channel[out], uint8_t
 * @return ms_hal_result_t
 */
ms_hal_result_t ms_hal_wifi_get_channel(uint8_t *channel);

/**
 * @brief start wifi ap model
 * @note  if device in sta model, please stop it.
 * @note  if device in ap model, please update ap information.
 * @param route_info[in]
 * @return ms_hal_result_t 
 */
ms_hal_result_t ms_hal_wifi_start_ap(ms_hal_wifi_softap_info_t *route_info);

/**
 * @brief stop wifi ap model
 * @note  if device in sta model, you need to close it, clear network configure information and connect error information.
 *        if device in other model, not do someting.
 * @param NULL 
 * @return NULL 
 */
void ms_hal_wifi_stop_ap(void);

/**
 * @brief stop wifi sta model
 * @note  if device in sta model, you need to close it, clear network configure information and connect error information.
 *        if device in other model, not do someting.
 * @param NULL 
 * @return NULL 
 */
void ms_hal_wifi_close_sta(void);

/**
 * @brief start wifi sta model
 * @note  if device in sta model, please update sta information.
 *        if device in ap model, please stop it.
 * @param chan[in] : ap/router channel
 *              if value is 0, you need scan all channel, 
 *              if value is other, such as 1~13, you need scan (1~13) it first. if not find ap, scan all channel.
 * @param p_stored_info[in] : please see ms_hal_wifi_route_t
 * @param use_bssid: 1: prescribe a limit to bssid;0:no limitation
 * @return ms_hal_result_t 
 */
ms_hal_result_t ms_hal_wifi_connect_ap(int8_t chan, ms_hal_wifi_route_t *p_stored_info, ms_hal_wifi_connect_param_t *param);

/**
 * @brief start wifi, initialize
 * @note  if device power on, will call it.
 * @param event_handler[in] : please see ms_hal_wifi_event_handler_t
 * @param errcode_report_callback[in] : please see ms_hal_wifi_status_report_func_t
 * @return ms_hal_result_t 
 */
ms_hal_result_t ms_hal_wifi_start(ms_hal_wifi_event_handler_t event_handler, ms_hal_wifi_status_report_func_t errcode_report_callback);

/**
 * @brief start wifi scan model
 * @note  
 * @param scan_param : please see ms_hal_wifi_ap_scan_param_t
 * @return ms_hal_result_t 
 */
ms_hal_result_t ms_hal_wifi_start_scan(ms_hal_wifi_ap_scan_param_t *scan_param);

/**
 * @brief stop wifi scan model
 * @note  
 * @param NULL
 * @return ms_hal_result_t 
 */
ms_hal_result_t ms_hal_wifi_stop_scan(void);

/**
 * @brief get wifi signal value
 * @note  
 * @param NULL
 * @return signal, see the rule.
            if rssi < -90, signal = 0
            else if rssi_value < -84, signal = 1
            else if rssi_value < -76, signal = 2
            else if rssi_value < -70, signal = 3
            else signal = 4;
 */
uint8_t ms_hal_wifi_get_signal(void);


/**
* @brief This function set country code.
* @param [in]ms_hal_wifi_country_code_t
* @return ms_hal_result_t
*/
ms_hal_result_t ms_hal_wifi_set_country_code(const ms_hal_wifi_country_code_t *country);

/**
* @brief This function get country code.
* @param [out]ms_hal_wifi_country_code_t
* @return ms_hal_result_t
*/
ms_hal_result_t ms_hal_wifi_get_country_code(ms_hal_wifi_country_code_t *country);

/**
* @brief This function set microwave disturb mode.
* @param [out]void
* @return void
*/
void ms_hal_microwave_disturb_enable(void);

/**
* @brief This function read reboot reason.
* @param [out]void
* @return uint32_t
*/
ms_hal_wifi_reboot_reason_t ms_hal_get_reboot_type(void);

#ifdef __cplusplus
}
#endif

#endif

